/*
 * @Author: 'Chenfarry' '2925102113@qq.com'
 * @Date: 2024-03-13 15:54:54
 * @LastEditors: 'Chenfarry' '2925102113@qq.com'
 * @LastEditTime: 2024-08-07 11:01:41
 * @FilePath: \liuyanggui\src\store\modules\settings.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from "pinia";
import defaultSettings from "@/settings";

export const useSettingsStore = defineStore("setting", () => {
  const layout = useStorage<string>("layout", defaultSettings.layout);
  const themeColor = useStorage<string>(
    "themeColor",
    defaultSettings.themeColor
  );
  const theme = useStorage<string>("theme", defaultSettings.theme);

  // Whether to enable watermark
  // const watermark = useStorage<any>("watermark", defaultSettings.watermark);

  const settingsMap: Record<string, Ref<any>> = {
    // showSettings,
    // fixedHeader,
    // tagsView,
    // sidebarLogo,
    layout,
    themeColor,
    theme,
    // watermark: watermark.value,
  };

  function changeSetting({ key, value }: { key: string; value: any }) {
    const setting = settingsMap[key];
    if (setting !== undefined) {
      setting.value = value;
      if (key === "theme" && value === "dark") {
        document.documentElement.classList.add("dark");
      } else {
        document.documentElement.classList.remove("dark");
      }
    }
  }

  return {
    // title,
    // version,
    // showSettings,
    // tagsView,
    // fixedHeader,
    // sidebarLogo,
    layout,
    themeColor,
    changeSetting,
    theme,
    // watermark,
  };
});
